package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.LocaleWorkQueryCount;
import com.isunland.managesystem.utils.MyUtils;
import java.util.ArrayList;

public class LocaleWorkQueryCountAdapter<T> extends BaseAdapter {

  private ArrayList<T> objects = new ArrayList<>();

  private Context context;
  private LayoutInflater layoutInflater;

  public LocaleWorkQueryCountAdapter(Context context, ArrayList<T> objects) {
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    this.objects = objects;
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView =
          layoutInflater.inflate(R.layout.adapter_locale_work_query_count_new, parent, false);
      convertView.setTag(new ViewHolder(convertView));
    }
    initializeViews(getItem(position), (ViewHolder) convertView.getTag(), position);
    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder, int position) {
    LocaleWorkQueryCount item = (LocaleWorkQueryCount) object;
    holder.tvDate.setText(item.getRegDate());
    //holder.tvTitle.setText(context.getString(R.string.operationNameHolder,item.getWorktypeshowvalue()==null?"":item.getWorktypeshowvalue()));
    holder.tvTaskName.setText(String.format("%s%s", context.getString(R.string.worktypeshowvalue),
        item.getWorktypeshowvalue()));
    holder.tvTitleRight.setVisibility(View.VISIBLE);
    //noinspection deprecation
    holder.tvTitleRight.setTextColor(context.getResources().getColor(R.color.dark_grey));
    holder.tvTitleRight.setText((position + 1) + "/" + getCount());
    holder.tvName.setText(item.getJoinStaffName());
    holder.tvMoney.setText(context.getString(R.string.yuanHolder,
        TextUtils.isEmpty(item.getTotalcost()) ? "0.0" : item.getTotalcost()));
    MyUtils.switchShadowStutus(context, holder.tvContentRight, item.getDataStatus(),
        item.getDataStatusName());//数据状态
  }

  static class ViewHolder {
    @BindView(R.id.tv_bottomLeft) TextView tvDate;
    @BindView(R.id.tv_title) TextView tvTaskName;
    @BindView(R.id.tv_content) TextView tvName;
    @BindView(R.id.tv_bottomRight) TextView tvMoney;
    @BindView(R.id.tv_contentRight) TextView tvContentRight;
    @BindView(R.id.tv_titleRight) TextView tvTitleRight;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }

  //    @Override
  //    public boolean isEmpty() {
  //        return false;
  //    }
}
